package com.john.pplay.util;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by stark on 2018/6/30.
 */

public class Circle extends View {

    private final String TAG = "Circle";
    private float circle_r = 80;
    private float lineSize = 20;
    private Paint painter1;
    private float percent = 100;
    private boolean show = false;
    public Circle(Context context) {
        super(context);
        painter1 = new Paint();
    }

    public Circle(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        painter1 = new Paint();
    }

    public Circle(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        painter1 = new Paint();
    }

    public void show(boolean show){
        MyLog.PrintLog(TAG," show "+show);
        this.show = show;
        this.postInvalidate();
    }
    @Override
    public void onDraw(Canvas canvas){
        super.onDraw(canvas);
//        MyLog.PrintLog(this.toString()," onDraw "+show);
        if (show) {
            lineSize = circle_r * (1 - percent / 100);
            percent++;
            if (percent >= 100) {
                percent = 0;
            }
            painter1.setColor(Color.GRAY);
            painter1.setStrokeWidth(lineSize);
            painter1.setStyle(Paint.Style.STROKE);
            canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, circle_r, painter1);
            invalidate();
        }
    }
}
